<div class="row" style="height:30px;">

</div>
<% for i in @team_list %>
  <div class="team_black">
    <div class="div_center">
      <h5><%=i["team_name"]%></h5>
      <div class="hidden-on" id="team_id"><%=i["team_id"]%></div>
    </div>
    <div class="row">
      <div class="col-xs-6 col-md-4">选择评价等级</div>
      <div class="col-xs-6 col-md-4">
        <select name="level">
          <option value ="1">优秀</option>
          <option value ="2" selected="selected">良好</option>
          <option value="3">一般</option>
          <option value="4">较差</option>
        </select>
      </div>
    </div>
    <div class="row">
      <div class="col-xs-6 col-md-4 input-line">请输入85-94范围内分值</div>
      <div class="col-xs-6 col-md-4">
        <input class="input_border" type="text" name="" value="">
      </div>
    </div>
    <div class="row hidden-on">
      <div class="col-xs-6 col-md-4 input-line2">请输入原因</div>
      <div class="col-xs-6 col-md-4">
        <textarea class="form-control" rows="3" name="" value="" ></textarea>
      </div>
    </div>
    <div class="demo_line_02"></div>
  </div>
<%end%>
  <div class="row">
  <%= form_tag("/scores/save_team_score", method: "post", multipart: true) do %>
    <div class="button-center">
      <input type="text"  name="license_key" class="hidden-on" value="<%=@license_key%>">
      <input type="hidden" id="team-data" name="team_data" value="">
      <button type="button" id="save-button" class="btn btn-primary btn-lg">提交</button>
    </div>
    <%end%>
  </div>
  <button type="button"  id = "tanchu" class="btn btn-primary btn-lg" style="display:none" data-toggle="modal" data-target="#myModal">
  </button>
  <button type="button"  id = "tanchu2" class="btn btn-primary btn-lg" style="display:none" data-toggle="modal" data-target="#myModal2">
  </button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="myModalLabel">部门民主评议标准</h4>
        </div>
        <div class="modal-body explain-css">
          <div class="row">
            <h5>单位（部门）职责履行:</h5> 职责工作主动及时开展，不影响其他单位、部门工作及公司整体工作进度；按时保质完成集团、公司所下达的工作任务，报送的各项材料，无弄虚作假的情况。
          </div>
          <div class="row">
            <h5>单位（部门）间配合协作:</h5>从公司整体出发考虑问题，具有支持和服务意识，单位（部门）间协作工作按时保质保量完成；与其他单位（部门）保持顺畅沟通，敢于承担责任，无推诿扯皮现象。
          </div>
          <div class="row">
            <h5>单位（部门）内部管理:</h5>本单位（部门）内工作开展顺畅、分工明晰；工作氛围积极向上，团队凝聚力强；单位（部门）内员工工作状态良好，职业化程度较高，基本未出现员工违纪违规情况。
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" id="close-button" data-dismiss="modal">知道了</button>
        </div>
      </div>
    </div>
  </div>
  <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">提示</h4>
      </div>
      <div class="modal-body  explain-css">
        <div class="row">
          <h3>您评价的所有部门中，评价等级为“优秀”的个数不得超过6个，若超出6个，视为无效票。</h3>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">知道了</button>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
  $(document).ready(function(){
     $("#tanchu").click();
  });
  $("#close-button").click(function() {
    $("#tanchu2").click();
  });
  $("select").change(function(){
    if ($(this).val() == 1){
      $(this).parent().parent().next().find(".input-line").text("请输入95-100范围内分值") ;
      $(this).parent().parent().next().next().hide();
    }
    else if ($(this).val() == 2) {
      $(this).parent().parent().next().find(".input-line").text("请输入85-94范围内分值") ;
      $(this).parent().parent().next().next().hide();
    }
    else if ($(this).val() == 3) {
      $(this).parent().parent().next().find(".input-line").text("请输入75-84范围内分值") ;
      $(this).parent().parent().next().next().hide();
    }else  if ($(this).val() == 4){
      $(this).parent().parent().next().find(".input-line").text("请输入75分以下分值") ;

      $(this).parent().parent().next().next().show() ;
    }
  });
  $("#save-button").click(function () {
    var team_data = new Array()
    var subflag = 1
    var subnum = 0 
    $(".team_black").each(function(){
      score_data = new Object();
      var team_id = $(this).find("#team_id").text();
      var team_score = $(this).find("input").val();
      var team_level = $(this).find("select").val();
      var team_reason = $(this).find("textarea").val();
      if(team_level == 1){
        if (team_score>=95 && team_score<=100) {
            score_data.team_id = team_id;
            score_data.team_score = team_score;
            score_data.team_level = team_level;
            score_data.team_reason = team_reason;
            team_data.push(JSON.stringify(score_data));
            subnum = subnum + 1 
        }else {
          $(this).find("input")[0].focus(function(){
            $(this).find("input")[0].css("background-color","#FFFFCC");
          });
          subflag = 0
          alert("请输入正确的分数");
          return false;
        }
      }else if (team_level == 2) {
        if (team_score>=85 && team_score<=94) {
            score_data.team_id = team_id;
            score_data.team_score = team_score;
            score_data.team_level = team_level;
            score_data.team_reason = team_reason;
            team_data.push(JSON.stringify(score_data));
        }else {
          $(this).find("input")[0].focus(function(){
            $(this).find("input")[0].css("background-color","#FFFFCC");
          });
          subflag = 0
          alert("请输入正确的分数");
          return false;
        }
      }else if (team_level == 3) {
        if (team_score>=75 && team_score<=84) {
            score_data.team_id = team_id;
            score_data.team_score = team_score;
            score_data.team_level = team_level;
            score_data.team_reason = team_reason;
            team_data.push(JSON.stringify(score_data));
        }else {
          $(this).find("input")[0].focus(function(){
            $(this).find("input")[0].css("background-color","#FFFFCC");
          });
          subflag = 0
          alert("请输入正确的分数");
          return false;
        }
      }else if (team_level == 4) {
        if (team_score>0 && team_score<=74) {
          team_reason = $.trim(team_reason);
          if(team_reason!=null && team_reason!=""){
            score_data.team_id = team_id;
            score_data.team_score = team_score;
            score_data.team_level = team_level;
            score_data.team_reason = team_reason;
            team_data.push(JSON.stringify(score_data));
          }else{
            alert("请填写较差原因");
            $(this).find("textarea")[0].focus(function(){
              $(this).css("background-color","#FFFFCC");
            });
            subflag = 0
            return false;
          }     
        }else {
          $(this).find("input")[0].focus(function(){
            $(this).css("background-color","#FFFFCC");
          });
          subflag = 0
          alert("请输入正确的分数");
          return false;
        }
      }
    });
    if (subflag==1 && subnum <= 6 ){
      $("#team-data").val(JSON.stringify(team_data));
      $( "form" ).submit();
    }else if(subflag == 0){
      return false;
    }else if(subflag == 1 && subnum > 6){
      alert("优秀部门数不能多于6个");
    }
  })
</script>
